package GameEngine.Gui;

import processing.core.PGraphics;
import processing.core.PImage;
import GameEngine.Gui.Event.TouchEvent;
import GameEngine.helper.PAppletBridge;

public abstract class GuiElement {
	protected int PosX;
	protected int PosY;
	protected int ScreenX;
	protected int ScreenY;
	protected int width;
	protected int height;
	private boolean isActive;
	
	public GuiElement (int x, int y, int w, int h) {
		PosX = x;
		PosY = y;
		ScreenX = PosX;
		ScreenY = PosY;
		width = w;
		height = h;
		isActive = false;
	}

	public boolean inArea(TouchEvent e) {
		return inArea(e.getX(), e.getY());
	}

	public boolean inArea(int x, int y) {
		return checkRect(x, y) && isActive;
	}

	private boolean checkRect(int x, int y) {
		return ((x >= ScreenX) && (x <= ScreenX + width))
				&& ((y >= ScreenY) && (y <= ScreenY + height));
	}
	
	protected void updateScreenXY(int x, int y) {
		ScreenX = (int)(PAppletBridge.screenX(x, y));
		ScreenY = (int)(PAppletBridge.screenY(x, y));
	}

	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	public abstract void draw();
	public abstract void draw(PGraphics pg);
	public abstract void mouseOver(int x, int y);
	public abstract PImage toImage();

}
